package com.dou361.jjdxm_ijkplayer.utlis;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import com.dou361.jjdxm_ijkplayer.MyApplication;

import java.io.File;
import java.util.UUID;

/**
 * Created by zyh on 2017/4/17.
 * 配置类
 * 这个 类的变量使用 需要注意集中情况 ,CommonConfig.value  和 CommonConfig.intance().value有着严格的区别
 * init(Context context) 在这个方法初始化的之后才有的变量,使用 CommonConfig.intance().value
 * 其余  情况使用 CommonConfig.value
 * 防止出现 空数据 或者 因为权限改变导致的风险
 * by  zyh 18.3.2
 */

public class CommonConfig {

    private static CommonConfig me;

    public static CommonConfig instance() {
        if (me != null) {
            return me;
        } else {
            return me = new CommonConfig(MyApplication.Instance());
        }
    }

    public CommonConfig() {
        me = this;
    }

    public CommonConfig(Context context) {
        me = this;
        init(context);
    }

    /**
     * 手机信息
     */
    public static String PHONE_UUID = ""; // uuid
    public static String PHONE_BRAND = Build.BRAND; // 手机厂商
    public static String VERSION = "1.0"; // 接口版本
    public static int SDK_INT = Build.VERSION.SDK_INT; // SDK版本号api 25
    public static String RELEASE = Build.VERSION.RELEASE; // 系统版本号 7.1
    public static String PATH = "";
    public String CACHE = "";
    public String CRASH = "";
    //测试模式
    public static String agreeUrl="";//协议http/https
    public static String currentUrl = "";//webroot
    public static String domainName = "allcp88.com";//webroot
    //key
    public final static String KEY = "8zQSb7wwzUkWIVQax5kaZM4I";
    //    //用户状态广播
//    public final static String ACCOUNT_CHANGE = "accountchange";
    //中奖状态
    public final static String REDPOINT_STATE = "redpointstate";
    //微信登录
//    public static final String WEIXIN_APP_ID = "wxcf56f616734badd8";//用户的Id
    //网易七鱼客服
    public static final String QIYU_APP_ID = "a10f3fff38c60a5f57e5a859884b5439";//用户的Id
    //渠道名
    private static String cmdName;
    //渠道号
    private static String cmdID;
    //版本名字 1.0.0
    private static String appVersionname;
    /**
     * 提示信息
     */
    public static String NETERROE = "网络连接不可用";
    public static String registrationId="";//极光id
    public static boolean canConnect=false;//是否可以长连接
    public static boolean isConnecteD=true;//Socket开关
    //全局马甲包信息 默认值1 就是本包
    public int appId = 1;
    public final static int mainTabCount=4;//显示的tab数量
    //全局的 根据包名配置马甲包名字

    //    static {//切换环境
//        if(BuildConfig.URL_TYPE==3) {//line
//            agreeUrl= "https://";
//        }else {//other
//            agreeUrl= "http://";
//        }
//    }

    private void init(Context context) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
                && Environment.getExternalStorageDirectory().canWrite()) {
            // 有访问SDCARD
            File sdCardDir = Environment.getExternalStorageDirectory();
            PATH = sdCardDir.getPath() + "/caiying/";
        } else {
            PATH = "/caiying/";
        }
        CACHE = PATH + "cache/";
        CRASH = PATH + "crash/";
        initPath();
        getMajiaId(context);
        //将static数据清空
        cmdName = "";
        cmdID = "";
        appVersionname = "";
        //全局 图片配置类
//        imageResNet = (ImageResNet) FileUtils.getObject(context, "ImageResNet.dat");
        //        L.e(CommonConfig.imageResNet);
    }

    /**
     * 获取马甲包ID
     */
    private void getMajiaId(Context context) {
        switch (context.getApplicationInfo().processName) {
            case "com.yxkj.cy":
                appId = 1;
                break;
            case "com.yxkj.yqkk":
                appId = 2;
                break;
            case "com.yxkj.yqzc":
                appId = 3;
                break;
            default:
                appId = 1;
        }
    }

    /**
     * 实例化路径
     */
    private void initPath() {
        // 创建资源根路径
        File file = new File(PATH);
        if (!file.exists()) {
            file.mkdirs();
        }

        File cache = new File(CACHE);
        if (!cache.exists()) {
            cache.mkdirs();
        }
        File crash = new File(CRASH);
        if (!crash.exists()) {
            crash.mkdirs();
        }
    }



    public String getAppPath() {
        return PATH;
    }

    public String getAppCachePath() {
        return CACHE;
    }

}